-
Notifications
You must be signed in to change notification settings - Fork 116
Update peer socket address when peer already existsRefresh the stored address if an existing peer is added again #735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
I've assigned @tnull as a reviewer! |
|
🔔 1st Reminder Hey @tnull! This PR has been waiting for your review. |
|
🔔 2nd Reminder Hey @tnull! This PR has been waiting for your review. |
|
|
||
| if locked_peers.contains_key(&peer_info.node_id) { | ||
| return Ok(()); | ||
| match locked_peers.get_mut(&peer_info.node_id) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why we bother to first look it up if the following behavior is identical to insert anyways? Why then not just always insert?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense — I missed the inbound-channel case where we shouldn’t overwrite an existing peer address.
| pub(crate) fn add_peer(&self, peer_info: PeerInfo) -> Result<(), Error> { | ||
| let mut locked_peers = self.peers.write().unwrap(); | ||
|
|
||
| if locked_peers.contains_key(&peer_info.node_id) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't just drop this, as there are instances where we'd add_peer but don't want to override the peer address if we already have one (e.g., when adding peers for inbound channels in event.rs). To solves this, we should probably just introduce an override: bool flag that lets us not return early. Alternatively, we could have two different methods for updating or inserting a peer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make sure I implement this the way you expect: would you prefer:
(a) keeping add_peer but adding an explicit override_existing: bool, or
(b) splitting this into two methods (e.g. add_peer_if_missing and upsert_peer)?
I’m happy to update call sites accordingly once I know which behavior you want to be the default.
Fixes #700.
Previously, re-adding an existing peer would return early and ignore an
updated socket address, causing stale peer addresses to be persisted.
This change updates and persists the peer info when the address differs,
and adds a regression test covering the behavior.